package com.globalresources.business.impl;

import java.util.List;
import com.globalresources.business.inface.IMenuService;
import com.globalresources.dao.inface.IMenuDao;
import com.globalresources.po.Menu;

/**
 * @author aaron.lu(luzhiyuan) E-mail:atyuan.lu@gmail.com
 * @since 创建时间：Jul 22, 2009 12:48:56 AM
 */
public class MenuServiceImpl implements IMenuService {
	
	private IMenuDao menuDao;
	/**
	 * query menu 
	*@author aaron.lu(luzhiyuan)
	*@param auth
	*@return
	 */
	public List<Menu> getMenus(String auth){
        
		return menuDao.getMenus(auth);
	}
	
	
	/**
	 * query all menus 
	*@author songduanlei@gmail.com
	*@return null
	 */
	public List<Menu> listMenus(){
		return menuDao.findAll();
	}
	
	/**
	 * save the menu Service Impl
	*@author songduanlei@gmail.com
	*@param Object Menu
	*@return null
	 */
	public void saveMenus(Menu menu){	
	    	
		menuDao.saveMenus(menu);
	}
	
	
	/**
	 * save Or Update the menu Service Impl
	*@author songduanlei@gmail.com
	*@param Object Menu
	*@return null
	 */
	public void saveOrUpdateMenus(Menu menu){		
		
		menuDao.saveOrUpdateMenus(menu);
	}
	/**
	 * get Menu By Id
	*@author songduanlei@gmail.com
	*@param Object Menu
	*@return null
	 */
	public Menu getMenuById(Integer id){			
		return menuDao.getMenuById(id);
	}
	
	/**
	 * List Menu By Group
	 * 
	 * @author songduanlei@gmail.com
	 * @param null
	 * @return Menus
	 */
	public List<Menu> listByGroup(String id){
		return menuDao.findBySql("select menu from Menu menu where menu.groups.id='"+id+"' order by menu.sequence desc");		
	}
	
	/**
	 * List Menu By Author
	 * 
	 * @author songduanlei@gmail.com
	 * @param null
	 * @return List Menus
	 */
	public List<Menu> listByAuthor(String id){
		return menuDao.findBySql("select menu from Menu menu where menu.authority.id='"+id+"' order by menu.sequence desc");		
		
	}

	/**
	 *delete Menu
	 * 
	 * @author songduanlei@gmail.com
	 * @param null
	 * @return List Menus
	 */
	public boolean deleteMenuById(Integer id){
		return menuDao.deleteMenuById(id);
		
		
	}

	/**
	 * @return the menuDao
	 */
	public IMenuDao getMenuDao() {
		return menuDao;
	}


	/**
	 * @param menuDao the menuDao to set
	 */
	public void setMenuDao(IMenuDao menuDao) {
		this.menuDao = menuDao;
	}
	
	/**
	 * List Menu  Group
	 * 
	 * @author songduanlei@gmail.com
	 * @param null
	 * @return Menus
	 */
	public List<Menu> listGroup(){
		return menuDao.findBySql("from Menu menu group by menu.groups.groups");
	}
	
	/**
	 * List Menu Author
	 * 
	 * @author songduanlei@gmail.com
	 * @param null
	 * @return List Menus
	 */
	public List<Menu> listAuthor(){
		return menuDao.findBySql("from Menu menu group by menu.authority.authority");
	}
}
